31-next-permutation.py
problem: ---
problem:

Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.
If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order).
The replacement must be in-place and use only constant extra memory.
Here are some examples. Inputs are in the left-hand column and its corresponding outputs are in the right-hand column.

1,2,3 → 1,3,2
3,2,1 → 1,2,3
1,1,5 → 1,5,1
---

-----------------------------------------------------------------------
bug_fixes: ---
bug_fixes:
On line 4, the intent is to find the peak from the right side. However with the condition, the loop will skip the peak element. Changing the < operator to the >= operator will fix the mistake.
On line 16, j is decremented after each iteration. This will cause an infinite loop as i < j will always be true. Changing it to decrement j by 1, instead of increment, will fix teh mistake.
---

-----------------------------------------------------------------------
bug_desc: ---
bug_desc:

---

-----------------------------------------------------------------------
line_no: ---
line_no:
4
---

-----------------------------------------------------------------------
buggy_code: ---
buggy_code:
1. class Solution(object):
2.     def nextPermutation(self, nums):
3.         i = len(nums) - 2
4.         while i >= 0 and nums[i] < nums[i+1]:
5.             i -= 1
6.         if i >= 0:
7.             j = len(nums) - 1
8.             while j >= 0 and nums[j] <= nums[i]:
9.                 j -= 1
10.             nums[i], nums[j] = nums[j], nums[i]
11.         i += 1
12.         j = len(nums) - 1
13.         while i < j:
14.             nums[i], nums[j] = nums[j], nums[i]
15.             i += 1
16.             j += 1
---

-----------------------------------------------------------------------
correct_code: ---
correct_code:
1. class Solution(object):
2.     def nextPermutation(self, nums):
3.         i = len(nums) - 2
4.         while i >= 0 and nums[i] >= nums[i+1]:
5.             i -= 1
6.         if i >= 0:
7.             j = len(nums) - 1
8.             while j >= 0 and nums[j] <= nums[i]:
9.                 j -= 1
10.             nums[i], nums[j] = nums[j], nums[i]
11.         i += 1
12.         j = len(nums) - 1
13.         while i < j:
14.             nums[i], nums[j] = nums[j], nums[i]
15.             i += 1
16.             j -= 1
---

-----------------------------------------------------------------------
